//
//  FoodDetailViewController.m
//  babyMemoryPro
//
//  Created by student on 15-6-25.
//  Copyright (c) 2015年 niit. All rights reserved.
//

#import "FoodDetailViewController.h"
#import "UIImageView+WebCache.h"
#import "AFHTTPRequestOperationManager.h"
#import "TFHpple.h"
@interface FoodDetailViewController ()<UITableViewDataSource,UITableViewDelegate>{
    NSString *str;

}

@end

@implementation FoodDetailViewController
-(NSMutableArray *)list{
    if (!_list) {
        _list=[[NSMutableArray alloc]init];
    }
    return _list;
    
}
-(NSMutableArray *)imgList{
    if (!_imgList) {
        _imgList=[[NSMutableArray alloc]init];
    }
    return _imgList;
    
}
- (void)viewDidLoad {

    [super viewDidLoad];
//    str=self.url;
    self.lable1.text=self.icon1;
    self.lable2.text=self.icon2;
    self.lable3.text=self.icon3;
    self.lable4.text=self.icon4;
    self.label5.text=self.icon5;
    
    self.label6.text=self.icon6;
    NSURL *urlStr1=[NSURL URLWithString:str];
    NSURLRequest *requset1=[NSURLRequest requestWithURL:urlStr1];
    NSOperationQueue *queue1=[[NSOperationQueue alloc] init];
    [NSURLConnection sendAsynchronousRequest:requset1
                                       queue:queue1
                           completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError)
     {
         TFHpple *hpple=[TFHpple hppleWithHTMLData:data];
         NSString *xpathStr=@"//div [@class='large']/img";
         NSArray *arr1=[hpple searchWithXPathQuery:xpathStr];
         for(TFHppleElement *tmp in arr1)
         {
             NSDictionary *dict=[tmp attributes];
             [self.imgList addObject:dict[@"src"]];
             
             
         }
//         NSString *xpathStr1=@"//ul/li/a";
//         NSArray *arr2=[hpple searchWithXPathQuery:xpathStr1];
//         for(TFHppleElement *tmp in arr2)
//         {
//             NSDictionary *dict = tmp.attributes;
//             [self.urlList addObject:dict[@"href"]];
//         }
//         for (int i=0; i<self.urlList.count-17; i++) {
//             [self.list2 addObject:self.urlList[i]];
//         }
         
         dispatch_async(dispatch_get_main_queue(), ^{
//             [self.tableView reloadData];
         });
     }];
    
    NSLog(@"%@",self.imgList);
    
    
//    NSString *urlPic=[self.imgList[0] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSURL *url=[NSURL URLWithString:self.urlPic];
    SDWebImageOptions options=SDWebImageRetryFailed|SDWebImageLowPriority;
    [self.imgView sd_setImageWithURL:url placeholderImage:nil options:options progress:^(NSInteger receivedSize, NSInteger expectedSize) {
        NSLog(@"下载进度:%f",(double)receivedSize/expectedSize);
    } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        NSLog(@"图片加载完毕:%@",image);
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    if(section == 0)
    {
        return 1;
    }
    if(section == 1)
    {
        return 1;
    }
    if(section == 2)
    {
        return 1;
    }
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
//    UIImageView *imgView=(UIImageView *)[cell viewWithTag:100];
    
//    NSString *urlPic=[self.imgList[indexPath.row] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
//    NSURL *url=[NSURL URLWithString:urlPic];
//    SDWebImageOptions options=SDWebImageRetryFailed|SDWebImageLowPriority;
//    [imgView sd_setImageWithURL:url placeholderImage:nil options:options progress:^(NSInteger receivedSize, NSInteger expectedSize) {
//        NSLog(@"下载进度:%f",(double)receivedSize/expectedSize);
//    } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
//        NSLog(@"图片加载完毕:%@",image);
//    }];
    
    return cell;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
